<include file="header" />
<body>
<div class="wraper">
	<div class="load">
		<img class="load-bee" src="/assets/base/repair/images/load-bee.png"/>

	</div>
    <div class="top">
        <p><a href="javascript:history.back(-1)" class="iconfont icon-zuo fl-left"></a>地址管理</p>
    </div>
    <div class="list-box">
    	<volist name="data" id="vo">
        <div class="list clearfix <if condition='$vo.default eq 1'>check</if>">
            <div class="left fl-left"  data-id="{BEESCRM:$vo['address_id']}">
                <p>{BEESCRM:$vo['username']} {BEESCRM:$vo['mobile']}</p>
                <p class="sub">{BEESCRM:$vo['community_name']}{BEESCRM:$vo['building_name']}{BEESCRM:$vo['room']} </p>
            </div>
            <div class="right fl-left">
                <a href="javascript:void(0)"class="iconfont icon-del-round shanchu fl-right" data-id="{BEESCRM:$vo['address_id']}" ></a>
                <a href="{BEESCRM::U('base/Repair/addAddress',array('order_id'=>$order_id,'address_id'=>$vo['address_id'],'wechat_id'=>$wechat_id))}"class="iconfont icon-jzd_xiugaishuxing bianji fl-right"></a>
            </div>
        </div>
        </volist>
    </div>
    <div class="marginb-50"></div>
    <div class="btn-box">
    	<input type="hidden" value="{BEESCRM:$order_id}" id="order_id">
    	<input type="hidden" value="{BEESCRM:$restaurant_order_id}" id="restaurant_order_id">
        <a href="{BEESCRM::U('base/Repair/addAddress',array('wechat_id'=>$wechat_id,'order_id'=>$order_id))}" class="btn big">新增地址</a>
    </div>
</div>

<include file="commonJS" />
<script>
$(document).ready(function(){
	$('.list-box').on('click','.list',function(){
		$(this).addClass('check').siblings().removeClass('check');
	});

	$('.left').on('click',function(){
		var order_id=$('#order_id').val();
		var restaurant_order_id = $('#restaurant_order_id').val();

		var address_id=$(this).data('id');
		if(order_id){
			$.ajax({
				type:'post',
				dataType:'json',
				data:{'address_id':address_id},
				url:"{BEESCRM::U('base/Repair/addressDefault',array('wechat_id'=>$wechat_id))}/order_id/"+order_id,
				success:function(data){
					if(data.status=='S'){
						if(order_id){
							location.href ="{BEESCRM::U('base/Repair/createOrder',array('wechat_id'=>$wechat_id))}/order_id/"+order_id
						}
					}else{
						$.alert('error',data.message);
					}
				},
				error:function(){
					$.alert('error','通讯错误');
				}
			});
		}else if(restaurant_order_id){
			$.ajax({
				type:'post',
				dataType:'json',
				data:{'address_id':address_id},
				url:"{BEESCRM::U('base/Repair/addressDefault',array('wechat_id'=>$wechat_id))}/restaurant_order_id/"+restaurant_order_id,
				success:function(data){
					if(data.status=='S'){
						location.href ="{BEESCRM::U('/base/restaurant/confirmOrders',array('wechat_id'=>$wechat_id))}/order_id/"+restaurant_order_id;
					}else{
						$.alert('error',data.message);
					}
				},
				error:function(){
					$.alert('error','通讯错误');
				}
			});
		}

	});
	//删除显示confirm框
	$(document).on('click','.icon-del-round',function(){
		var address_id=$(this).data('id');
		var msg = '确认删除该条地址';
		if(confirm(msg)){
			delLight(address_id)
		}else{
			return false;
		}
	});
	//确认删除
	function delLight(address_id){
		if(address_id == ''){
			$.alert('error','参数错误');
		}else{
			$.ajax({
				type : 'post',
				dataType : 'json',
				data : {'address_id':address_id,'cut_off':1},
				url : "{BEESCRM::U('base/Repair/delAddress',array('wechat_id'=>$wechat_id))}",
				success : function(data) {
					if (data.status == 'S') {
						$.alert('error',data.message);
						setTimeout( "window.location.reload()", 2000);
					} else {
						$.alert('error',data.message);
					}
				},
				error : function(data) {
					$.alert('error','参数错误');
				}
			});
		}
	}
});
</script>
</body>

</html>
